home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / MacSNMP / SNMP Agents Dev Kit / Library Manager Interfaces / LibraryManager.h next >
Encoding:
C/C++ Source or Header  |  1994-11-21  |  41.8 KB  |  1,474 lines  |  [TEXT/MPS ]

  1. /*    File:        LibraryManager.h
  2.  
  3.     Contains:    Minimal declarations you need to use the ASLM.
  4.  
  5.     Copyright:    © 1991-1993 by Apple Computer, Inc., all rights reserved.
  6.  
  7.  
  8. */
  9.  
  10. #ifndef __LIBRARYMANAGER__
  11. #define __LIBRARYMANAGER__
  12.  
  13. #if defined(powerpc) || defined(__powerpc)
  14.     #define ASLM_COMPATIBLE    /* */
  15.     #define MAC68K                0
  16.     #define VOLATILE            volatile
  17.     #define SINGLEOBJECT        0
  18.     #define MPWC
  19.     #ifndef __CONDITIONALMACROS__
  20.         #ifndef SystemSevenOrLater
  21.         #define SystemSevenOrLater        1
  22.         #endif
  23.         #ifndef USES68KINLINES
  24.         #define USES68KINLINES            0
  25.         #endif
  26.         #ifndef USESROUTINEDESCRIPTORS
  27.         #define USESROUTINEDESCRIPTORS    1
  28.         #endif
  29.         #ifndef USESCODEFRAGMENTS
  30.         #define USESCODEFRAGMENTS        1
  31.         #endif
  32.     #endif
  33. #else
  34.     #define MAC68K                1
  35.     #if defined(__SC__)
  36.         #if !NoDummyVTableSlot
  37.             #define ASLM_COMPATIBLE                                \
  38.                 private:                                        \
  39.                     virtual        void DummyVirtualFunction();
  40.                     
  41.             #define ASLM_SCDECLARATION(className)        \
  42.             void className::DummyVirtualFunction() {}
  43.         #else
  44.             #define ASLM_COMPATIBLE        /* */
  45.             #define ASLM_SCDECLARATION    /* */
  46.         #endif
  47.         
  48.         #define VOLATILE        volatile
  49.         #define SINGLEOBJECT    0
  50.         #define MPWC            _cdecl
  51.     #else
  52.         #define ASLM_COMPATIBLE    /* */
  53.         #define VOLATILE
  54.         #define SINGLEOBJECT    1
  55.         #define MPWC
  56.     #endif
  57.     #ifndef __CONDITIONALMACROS__
  58.         #ifndef SystemSevenOrLater
  59.         #define SystemSevenOrLater        0
  60.         #endif
  61.         #ifndef USES68KINLINES
  62.         #define USES68KINLINES            1
  63.         #endif
  64.         #ifndef USESROUTINEDESCRIPTORS
  65.         #define USESROUTINEDESCRIPTORS    0
  66.         #endif
  67.         #ifndef USESCODEFRAGMENTS
  68.         #define USESCODEFRAGMENTS        0
  69.         #endif
  70.     #endif
  71. #endif
  72.  
  73. #ifndef OLDROUTINENAMES
  74. #define OLDROUTINENAMES 1
  75. #endif
  76.  
  77. #undef SystemSixOrLater
  78. #define SystemSixOrLater    1
  79.  
  80. #ifndef __STDDEF__
  81. #include <stddef.h>
  82. #endif
  83. #ifndef __STRING__
  84. #undef    NULL
  85. #include <String.h>
  86. #endif
  87.  
  88. #if !defined(__SC__)
  89.     #ifndef __TYPES__
  90.     #include <Types.h>
  91.     #endif
  92. #endif
  93.  
  94. /*******************************************************************************
  95. ** Some Typedefs and constants
  96. ********************************************************************************/
  97.  
  98. #ifndef NULL
  99. #define NULL        0
  100. #endif
  101.  
  102. #ifndef __TYPES__
  103. typedef char*            Ptr;
  104. typedef short            OSErr;
  105. typedef long             (*ProcPtr)();
  106. typedef unsigned char    Boolean;
  107. typedef unsigned long    ResType;
  108. typedef unsigned char     Str63[64];
  109.  
  110. #define false    ((Boolean)0)
  111. #define true    ((Boolean)1)
  112. #endif
  113.  
  114. //
  115. //    The following are parameter typedefs to force Symantec compilers to pass
  116. //    one byte parameters as two byte parameters so you can call MPW built
  117. //    shared libraries from Symantec built clients.
  118. //
  119. #if MAC68K
  120.     typedef    int                OSErrParm;
  121.     typedef unsigned int    BooleanParm;
  122.     typedef int                charParm;
  123.     typedef unsigned int    ucharParm;
  124.     typedef int                shortParm;
  125.     typedef unsigned int    ushortParm;
  126.     typedef long double        floatParm;
  127.     typedef long double        doubleParm;
  128. #else
  129.     typedef    OSErr            OSErrParm;
  130.     typedef Boolean            BooleanParm;
  131.     typedef char            charParm;
  132.     typedef unsigned char    ucharParm;
  133.     typedef short            shortParm;
  134.     typedef unsigned short    ushortParm;
  135.     typedef float            floatParm;
  136.     typedef double            doubleParm;
  137. #endif
  138.  
  139. /*******************************************************************************
  140. ** Some external routines
  141. ********************************************************************************/
  142.  
  143. #ifdef __cplusplus
  144. extern "C" {
  145. #endif
  146.     char* strcpy(char* s1, const char* s2);
  147. #ifdef __cplusplus
  148. };
  149. #endif
  150.  
  151. /*******************************************************************************
  152. ** Error Constants
  153. ********************************************************************************/
  154.  
  155. #define kNoError                        0
  156. #define kNotFound                        -3120
  157. #define kNoParent                        -3121
  158. #define kParentNotFound                    -3122
  159. #define kNotRelated                        -3123
  160. #define kInvalidObject                    -3124
  161. #define kPoolCorrupted                    -3125
  162. #define kOutOfMemory                    -3126
  163. #define kCodeNotLoaded                    -3127
  164. #define kCouldNotLoadCode                -3128
  165. #define kFilePreflighted                -3129
  166. #define kFileNotPreflighted                -3130
  167. #define kFileNotFound                    -3131
  168. #define kLibraryManagerNotLoaded        -3132
  169. #define kDuplicateFound                    -3134
  170. #define kSeedChanged                    -3135
  171. #define kUnconstructedObject            -3136
  172. #define kInternalError                    -3137
  173. #define kVersionError                    -3138
  174. #define kFolderNotFound                    -3139
  175. #define kFolderInUse                    -3140
  176. #define kResourceNotFound                -3141
  177. #define kNotAllowedNow                    -3155
  178. #define kNotSupported                    -3167
  179.     
  180. #define kASLMNotFoundErr                -3120
  181. #define kASLMNoParentErr                -3121
  182. #define kASLMParentNotFoundErr            -3122
  183. #define kASLMNotRelatedErr                -3123
  184. #define kASLMInvalidObjectErr            -3124
  185. #define kASLMPoolCorruptedErr            -3125
  186. #define kASLMOutOfMemoryErr                -3126
  187. #define kASLMCodeNotLoadedErr            -3127
  188. #define kASLMCouldNotLoadCodeErr        -3128
  189. #define kASLMFilePreflightedErr            -3129
  190. #define kASLMFileNotPreflightedErr        -3130
  191. #define kASLMFileNotFoundErr            -3131
  192. #define kASLMLibraryManagerNotLoadedErr    -3132
  193. #define kASLMDuplicateFoundErr            -3134
  194. #define kASLMSeedChangedErr                -3135
  195. #define kASLMUnconstructedObjectErr        -3136
  196. #define kASLMInternalErr                -3137
  197. #define kASLMVersionErr                    -3138
  198. #define kASLMFolderNotFoundErr            -3139
  199. #define kASLMFolderInUseErr                -3140
  200. #define kASLMResourceNotFoundErr        -3141
  201. #define kASLMNotAllowedNowErr            -3155
  202. #define kASLMNotSupportedErr            -3167
  203.  
  204. /*******************************************************************************
  205. ** Typedefs
  206. ********************************************************************************/
  207.  
  208. typedef void*            GlobalWorld;
  209. #define kInvalidWorld    ((GlobalWorld)0)
  210.  
  211. typedef unsigned short    Version;
  212. #define kAnyVersion        ((Version)0)
  213.  
  214. #define    TFunctionSetID    TClassID
  215. #define    TLibraryID        TClassID
  216. #define    FunctionSetID    ClassID        /* for casting a cstring to a TFunctionSetID */
  217. #define    LibraryID        ClassID        /* for casting a cstring to a TLibraryID */
  218.  
  219. /*******************************************************************************
  220. ** Forward class declarations
  221. ********************************************************************************/
  222.  
  223. #ifdef __cplusplus
  224.     class    TDynamic;
  225.     class    TLibraryManager;
  226.     class    TClassID;
  227.     class    TFunctionSetID;
  228.     class    TLibraryID;
  229.     class    TLibrary;
  230.     class    TFormattedStream;
  231.     class    TMemoryPool;
  232.     class    TStandardPool;
  233.     class    TLibraryFile;
  234.     class     TClassInfo;
  235.     class    TException;
  236.     class    TSimpleList;
  237.     class    TFileSpec;
  238. #else
  239.     typedef char* TClassID;
  240.     typedef void TDynamic;
  241.     typedef void TLibraryManager;
  242.     typedef void TFormattedStream;
  243.     typedef void TStandardPool;
  244.     typedef void TClassInfo;
  245.     typedef void TLibrary;
  246.     typedef void TMemoryPool;
  247. #endif
  248.  
  249.  
  250. /*******************************************************************************
  251. ** Memory definitions
  252. ********************************************************************************/
  253.  
  254. typedef int    ZoneType;
  255.  
  256. #define kSystemZone                ((ZoneType)1)
  257. #define kKernelZone                ((ZoneType)2)
  258. #define kApplicZone                ((ZoneType)3)
  259. #define kCurrentZone            ((ZoneType)4)
  260. #define kTempZone                ((ZoneType)5)
  261.  
  262. typedef int    MemoryType;
  263.  
  264. #define kNormalMemory            ((MemoryType)1)
  265. #define kHoldMemory                ((MemoryType)2)
  266. #define kLockMemory                ((MemoryType)3)
  267. #define kLockMemoryContiguous    ((MemoryType)4)
  268.  
  269. /*******************************************************************************
  270. ** STACKOBJECTONLY: Use in a class declaration so the object can only be created
  271. ** on the stack. This makes the constructors and destructors much smaller since
  272. ** they know they will never have to new or delete memory.
  273. ********************************************************************************/
  274.  
  275. #define STACKOBJECTONLY                                                \
  276.     private:                                                        \
  277.                 void*    operator new(size_t) { return NULL; }        \
  278.                 void    operator delete(void*) {}
  279.  
  280. /*******************************************************************************
  281. ** Some "C" Global routines
  282. **
  283. ** InitLibraryManager initializes a client to use the ASLM. All clients
  284. ** must make this call except for ASLM libraries. CleanupLibraryManager
  285. ** should be called when the client is done using the ASLM.
  286. **
  287. ** GetLocalLibraryManager can be called after InitLibraryManager is called. If it
  288. ** returns NULL then InitLibraryManager failed.
  289. ********************************************************************************/
  290.  
  291. #ifdef __cplusplus
  292.     extern "C" {
  293. #endif
  294.  
  295. /*    -------------------------------------------------------------------------
  296.     These functions are for use by applications or stand-alone code 
  297.     resources only
  298.     ------------------------------------------------------------------------- */
  299.  
  300. #ifdef __cplusplus
  301.         
  302. OSErr                InitLibraryManager(size_t poolsize = 0, ZoneType = kCurrentZone,
  303.                                        MemoryType = kNormalMemory);
  304. void                CleanupLibraryManager();
  305.     
  306. #else
  307.  
  308. OSErr                InitLibraryManager(size_t poolsize, int zoneType, int memType);
  309. void                CleanupLibraryManager(void);
  310.     
  311. #endif
  312.  
  313. /*    -------------------------------------------------------------------------
  314.     These functions can be used by any Shared Library Manager clients
  315.     ------------------------------------------------------------------------- */
  316.  
  317. #ifdef __cplusplus
  318.  
  319. Boolean                IsDerivedFrom(const void*, const TClassID&);
  320. const TClassID&        GetObjectsClassID(const void*);
  321. const TClassID&        GetObjectsParentClassID(const void*);
  322. size_t                GetObjectsSize(const void*);
  323. TLibrary*            GetObjectsLocalLibrary(const void*);
  324. TLibraryFile*        GetObjectsLocalLibraryFile(const void*);
  325. TStandardPool*        GetObjectsLocalPool(const void*);
  326. void                SetObjectsLocalPool(const void*, TStandardPool*);
  327.  
  328. void*                NewObject(const TClassID&, OSErr* = NULL,
  329.                               TStandardPool* = NULL);
  330. void*                NewObjectWithParent(const TClassID&,
  331.                                         const TClassID& parentID,
  332.                                         OSErr* = NULL, TStandardPool* = NULL);
  333. void*                NewObjectFromStream(const TFormattedStream&,
  334.                                         OSErr* = NULL, TStandardPool* = NULL);
  335.  
  336. TClassInfo*         GetClassInfo(const TClassID&, OSErr* = NULL);
  337.  
  338. OSErr                VerifyClass(const TClassID&, const TClassID& parentID);
  339. void*                CastObject(const void*, const TClassID& parentID, OSErr* = NULL);
  340. void*                CastToMainObject(const void*);
  341.  
  342. OSErr                LoadClass(const TClassID&, BooleanParm forceAll);
  343. OSErr                UnloadClass(const TClassID&);
  344. Boolean                IsClassLoaded(const TClassID&);
  345.  
  346. OSErr                LoadFunctionSet(const TFunctionSetID&, BooleanParm forceAll);
  347. OSErr                UnloadFunctionSet(const TFunctionSetID&);
  348. Boolean                IsFunctionSetLoaded(const TFunctionSetID&);
  349.  
  350. ProcPtr                GetFunctionPointer(const TFunctionSetID&, const char* funcName,
  351.                                        OSErr* = NULL);
  352. ProcPtr                GetIndexedFunctionPointer(const TFunctionSetID&, unsigned int index,
  353.                                               OSErr* = NULL);
  354.  
  355. OSErr                LoadLibraries(BooleanParm forceAll = true,
  356.                                   BooleanParm doSelf = true);
  357. OSErr                UnloadLibraries();
  358. void                ResetFunctionSet(const TFunctionSetID* = NULL);
  359.         
  360. Boolean                TraceLogOn();
  361. Boolean                TraceLogOff();
  362.  
  363. void                RegisterDynamicObject(TDynamic*);
  364. void                UnregisterDynamicObject(TDynamic*);
  365.     
  366. TLibraryManager*    GetLocalLibraryManager();
  367.     
  368. TStandardPool*        GetLocalPool();
  369. void                SetLocalPool(TStandardPool*);
  370. TStandardPool*        GetClientPool();
  371. TStandardPool*        GetDefaultPool();
  372. void                SetDefaultPool(TStandardPool*);
  373. TStandardPool*        GetSystemPool();
  374.     
  375. #else
  376.     
  377. void*                NewObject(const TClassID, OSErr*, TStandardPool*);
  378. void*                NewObjectWithParent(const TClassID, const TClassID parentID,
  379.                                         OSErr*, TStandardPool*);
  380. void*                NewObjectFromStream(const TFormattedStream*, OSErr*,
  381.                                         TStandardPool*);
  382.  
  383. TClassInfo*         GetClassInfo(const TClassID, OSErr*);
  384.  
  385. OSErr                VerifyClass(const TClassID, const TClassID parentID);
  386. void*                CastObject(const void*, const TClassID parentID, OSErr*);
  387. void*                CastToMainObject(const void*);
  388.  
  389. OSErr                LoadClass(const TClassID, BooleanParm forceAll);
  390. OSErr                UnloadClass(const TClassID);
  391. Boolean                IsClassLoaded(const TClassID);
  392.  
  393. OSErr                LoadFunctionSet(const TFunctionSetID, BooleanParm forceAll);
  394. OSErr                UnloadFunctionSet(const TFunctionSetID);
  395. Boolean                IsFunctionSetLoaded(const TFunctionSetID);
  396.  
  397. ProcPtr                GetFunctionPointer(const TFunctionSetID, const char* funcName,
  398.                                        OSErr*);
  399. ProcPtr                GetIndexedFunctionPointer(const TFunctionSetID, unsigned int index,
  400.                                               OSErr*);
  401.  
  402. OSErr                LoadLibraries(BooleanParm forceAll, BooleanParm doSelf);
  403. OSErr                UnloadLibraries(void);
  404. void                ResetFunctionSet(const TFunctionSetID);
  405.         
  406. Boolean                TraceLogOn();
  407. Boolean                TraceLogOff();
  408.  
  409. TLibraryManager*    GetLocalLibraryManager(void);
  410.  
  411. TStandardPool*        GetLocalPool();
  412. void                SetLocalPool(TStandardPool*);
  413. TStandardPool*        GetClientPool();
  414. TStandardPool*        GetDefaultPool();
  415. void                SetDefaultPool(TStandardPool*);
  416. TStandardPool*        GetSystemPool();
  417.  
  418. #endif
  419.  
  420. /*    -------------------------------------------------------------------------
  421.     These functions are only used for their inline value.
  422.     Do not call them directly.
  423.     ------------------------------------------------------------------------- */
  424.  
  425. #ifdef __cplusplus
  426.     extern void* SLMNewOperator(size_t, TMemoryPool*);
  427.     extern void SLMDeleteOperator(void*);
  428. }
  429.  
  430. /*******************************************************************************
  431. ** CLASS TSimpleDynamic
  432. **
  433. ** A base class for shared-library classes that has no virtual functions.  This
  434. ** class is NOT shared, since it is intended to be a trivial class that just
  435. ** forces the VTable to be at the front of the object.
  436. ********************************************************************************/
  437.  
  438. #if SINGLEOBJECT
  439. class TSimpleDynamic : public SingleObject
  440. #else
  441. class TSimpleDynamic
  442. #endif
  443. {
  444.     ASLM_COMPATIBLE
  445.  
  446.     public:
  447.         virtual                  ~ MPWC TSimpleDynamic();
  448.         
  449.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  450.                                     { return SLMNewOperator(size, pool); }
  451.                 void*            operator new(size_t size)                        // from default pool
  452.                                     { return SLMNewOperator(size, 0); }
  453.                 void            operator delete(void* obj, size_t)
  454.                                     { SLMDeleteOperator(obj); }
  455.  
  456.                 const TClassID&    MPWC GetObjectsClassID() const;
  457.                 const TClassID&    MPWC GetObjectsParentClassID() const;
  458.                 size_t            MPWC GetObjectsSize() const;
  459.                 TLibrary*        MPWC GetObjectsLocalLibrary() const;
  460.                 TLibraryFile*    MPWC GetObjectsLocalLibraryFile() const;
  461.                 TStandardPool*    MPWC GetObjectsLocalPool() const;
  462.                 void            MPWC SetObjectsLocalPool(TStandardPool*) const;
  463.     
  464.                 Boolean            MPWC IsDerivedFrom(const TClassID&) const;
  465.                 
  466.     protected:
  467.                                   MPWC TSimpleDynamic();
  468.  
  469.     private:
  470.                                 TSimpleDynamic(const TSimpleDynamic&);
  471.                 void            operator=(const TSimpleDynamic&);
  472. };
  473.  
  474. /*******************************************************************************
  475. ** CLASS TDynamic
  476. **
  477. ** The base class for shared-library classes with a set of common capabilities.
  478. ** This class provides the same capabilities as TStdDynamic.
  479. ********************************************************************************/
  480.  
  481. typedef int    TraceControlType;
  482.  
  483. #define kTraceStatus    ((TraceControlType)1)
  484. #define kTraceOn        ((TraceControlType)2)
  485. #define kTraceOff        ((TraceControlType)3)
  486.  
  487. #define kTDynamicID "!$dyna,1.1"
  488.  
  489. #if SINGLEOBJECT
  490. class TDynamic : public SingleObject
  491. #else
  492. class TDynamic
  493. #endif
  494. {
  495.     ASLM_COMPATIBLE
  496.  
  497.     public:
  498.         virtual                  ~ MPWC TDynamic();
  499.         
  500.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  501.                                     { return SLMNewOperator(size, pool); }
  502.                 void*            operator new(size_t size)                        // from default pool
  503.                                     { return SLMNewOperator(size, 0); }
  504.                 void            operator delete(void* obj, size_t)
  505.                                     { SLMDeleteOperator(obj); }
  506.                                     
  507.  
  508.         const TClassID&            MPWC GetObjectsClassID() const;
  509.         const TClassID&            MPWC GetObjectsParentClassID() const;
  510.                 size_t            MPWC GetObjectsSize() const;
  511.                 TLibrary*        MPWC GetObjectsLocalLibrary() const;
  512.                 TLibraryFile*    MPWC GetObjectsLocalLibraryFile() const;
  513.                 TStandardPool*    MPWC GetObjectsLocalPool() const;
  514.                 void            MPWC SetObjectsLocalPool(TStandardPool*) const;
  515.  
  516.         virtual Boolean            MPWC IsValid() const;
  517.         
  518.         virtual    OSErr            MPWC Inflate(TFormattedStream&);
  519.         virtual OSErr            MPWC Flatten(TFormattedStream&) const;
  520.         virtual TDynamic*        MPWC Clone(TStandardPool*) const;
  521.         
  522.         virtual    char*            MPWC GetVerboseName(char*) const;
  523.         virtual    void            MPWC Dump() const;
  524.         
  525.                 void            MPWC Trace(char *formatStr, ...) const;
  526.         virtual    Boolean            MPWC TraceControl(TraceControlType) const;
  527.                 Boolean            MPWC IsTraceOn() const;    
  528.                 Boolean            MPWC TraceOn() const;
  529.                 Boolean            MPWC TraceOff() const;
  530.     
  531.                 Boolean            MPWC IsDerivedFrom(const TClassID&) const;
  532.                 
  533.     protected:
  534.                                   MPWC TDynamic();
  535.  
  536.     private:
  537.                                 TDynamic(const TDynamic&);
  538.                 void            operator=(const TDynamic&);
  539. };
  540.  
  541. /*    -------------------------------------------------------------------------
  542.     Inline methods for TDynamic
  543.     ------------------------------------------------------------------------- */
  544.  
  545.     inline Boolean TDynamic::IsTraceOn() const
  546.     {
  547.         return TraceControl(kTraceStatus);
  548.     }
  549.  
  550.     inline Boolean TDynamic::TraceOn() const
  551.     {
  552.         return TraceControl(kTraceOn);
  553.     }
  554.  
  555.     inline Boolean TDynamic::TraceOff() const
  556.     {
  557.         return TraceControl(kTraceOff);
  558.     }
  559.  
  560. /*******************************************************************************
  561. ** CLASS MDynamic
  562. **
  563. ** A base class for shared-library classes, which has one 1 virtual function (the
  564. ** destructor).  This class is NOT shared, since it is intended to be a trivial class
  565. ** that can be used to force the VTable to be at the front of the object for
  566. ** mixin classes.
  567. ********************************************************************************/
  568.  
  569. class MDynamic
  570. {
  571.     ASLM_COMPATIBLE
  572.  
  573.     public:
  574.         virtual                  ~MDynamic();
  575.         
  576.     protected:
  577.                                   MDynamic();
  578.  
  579.     private:
  580.                                 MDynamic(const MDynamic&);
  581.                 void            operator=(const MDynamic&);
  582. };
  583.  
  584. /*******************************************************************************
  585. ** CLASS TStdDynamic
  586. **
  587. ** The base class for shared-library classes with a set of common capabilities.
  588. ** This class provides the same capabilities as TDynamic below, but is for
  589. ** classes that you don't want to descend from SingleObject.
  590. ********************************************************************************/
  591.  
  592. #define kTStdDynamicID "!$sdyn,1.1"
  593.  
  594. class TStdDynamic
  595. {
  596.     ASLM_COMPATIBLE
  597.  
  598.     public:
  599.         virtual                  ~ MPWC TStdDynamic();
  600.         
  601.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  602.                                     { return SLMNewOperator(size, pool); }
  603.                 void*            operator new(size_t size)                        // from default pool
  604.                                     { return SLMNewOperator(size, 0); }
  605.                 void            operator delete(void* obj, size_t)
  606.                                     { SLMDeleteOperator(obj); }
  607.                                     
  608.  
  609.         const TClassID&            MPWC GetObjectsClassID() const;
  610.                 size_t            MPWC GetObjectsSize() const;
  611.                 TLibrary*        MPWC GetObjectsLocalLibrary() const;
  612.                 TLibraryFile*    MPWC GetObjectsLocalLibraryFile() const;
  613.                 TStandardPool*    MPWC GetObjectsLocalPool() const;
  614.                 void            MPWC SetObjectsLocalPool(TStandardPool*) const;
  615.  
  616.         virtual Boolean            MPWC IsValid() const;
  617.         
  618.         virtual    OSErr            MPWC Inflate(TFormattedStream&);
  619.         virtual OSErr            MPWC Flatten(TFormattedStream&) const;
  620.         virtual TDynamic*        MPWC Clone(TStandardPool*) const;
  621.         
  622.         virtual    char*            MPWC GetVerboseName(char*) const;
  623.         virtual    void            MPWC Dump() const;
  624.         
  625.                 void            MPWC Trace(char *formatStr, ...) const;
  626.         virtual    Boolean            MPWC TraceControl(TraceControlType) const;
  627.                 Boolean            IsTraceOn() const;    
  628.                 Boolean            TraceOn() const;
  629.                 Boolean            TraceOff() const;
  630.     
  631.                 Boolean            MPWC IsDerivedFrom(const TClassID&) const;
  632.                 
  633.     protected:
  634.                                   MPWC TStdDynamic();
  635.  
  636.     private:
  637.                                 TStdDynamic(const TDynamic&);
  638.                 void            operator=(const TDynamic&);
  639. };
  640.  
  641. /*    -------------------------------------------------------------------------
  642.     Inline methods for TStdDynamic
  643.     ------------------------------------------------------------------------- */
  644.  
  645.     inline Boolean TStdDynamic::IsTraceOn() const
  646.     {
  647.         return TraceControl(kTraceStatus);
  648.     }
  649.  
  650.     inline Boolean TStdDynamic::TraceOn() const
  651.     {
  652.         return TraceControl(kTraceOn);
  653.     }
  654.  
  655.     inline Boolean TStdDynamic::TraceOff() const
  656.     {
  657.         return TraceControl(kTraceOff);
  658.     }
  659.  
  660. /*******************************************************************************
  661. ** CLASS TStdSimpleDynamic
  662. **
  663. ** A base class for shared-library classes that has no virtual functions.  This
  664. ** class is NOT shared, since it is intended to be a trivial class that just
  665. ** forces the VTable to be at the front of the object.
  666. ********************************************************************************/
  667.  
  668. class TStdSimpleDynamic
  669. {
  670.     ASLM_COMPATIBLE
  671.  
  672.     public:
  673.         virtual                  ~ MPWC TStdSimpleDynamic();
  674.         
  675.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  676.                                     { return SLMNewOperator(size, pool); }
  677.                 void*            operator new(size_t size)                        // from default pool
  678.                                     { return SLMNewOperator(size, 0); }
  679.                 void            operator delete(void* obj, size_t)
  680.                                     { SLMDeleteOperator(obj); }
  681.  
  682.                 const TClassID&    MPWC GetObjectsClassID() const;
  683.                 size_t            MPWC GetObjectsSize() const;
  684.                 TLibrary*        MPWC GetObjectsLocalLibrary() const;
  685.                 TLibraryFile*    MPWC GetObjectsLocalLibraryFile() const;
  686.                 TStandardPool*    MPWC GetObjectsLocalPool() const;
  687.                 void            MPWC SetObjectsLocalPool(TStandardPool*) const;
  688.     
  689.                 Boolean            MPWC IsDerivedFrom(const TClassID&) const;
  690.                 
  691.     protected:
  692.                                   MPWC TStdSimpleDynamic();
  693.  
  694.     private:
  695.                                 TStdSimpleDynamic(const TStdSimpleDynamic&);
  696.                 void            operator=(const TStdSimpleDynamic&);
  697. };
  698.  
  699. #ifdef __SC__
  700.  
  701. /*******************************************************************************
  702. ** CLASS TSCSimpleDynamic
  703. **
  704. ** A base class for shared-library classes that has no virtual functions.  This
  705. ** class is NOT shared, since it is intended to be a trivial class that just
  706. ** forces the VTable to be at the front of the object, and override new to
  707. ** use the ASLM operators. It is used as a simple base class for Symantec C++ objects.
  708. ** This is the normal subclass for Symantec C++ objects that are not going to 
  709. ** intermix with MPW C++ objects.
  710. ********************************************************************************/
  711.  
  712. class TSCSimpleDynamic
  713. {
  714.     ASLM_COMPATIBLE
  715.  
  716.     public:
  717.         virtual                  ~TSCSimpleDynamic();
  718.         
  719.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  720.                                     { return SLMNewOperator(size, pool); }
  721.                 void*            operator new(size_t size)                        // from default pool
  722.                                     { return SLMNewOperator(size, 0); }
  723.                 void            operator delete(void* obj, size_t)
  724.                                     { SLMDeleteOperator(obj); }
  725.  
  726.                 const TClassID&    GetObjectsClassID() const;
  727.                 const TClassID&    GetObjectsParentClassID() const;
  728.                 size_t            GetObjectsSize() const;
  729.                 TLibrary*        GetObjectsLocalLibrary() const;
  730.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  731.                 TStandardPool*    GetObjectsLocalPool() const;
  732.                 void            SetObjectsLocalPool(TStandardPool*) const;
  733.     
  734.                 Boolean            IsDerivedFrom(const TClassID&) const;
  735.                 
  736.     protected:
  737.                                   TSCSimpleDynamic();
  738.  
  739.     private:
  740.                                 TSCSimpleDynamic(const TSCSimpleDynamic&);
  741.                 void            operator=(const TSCSimpleDynamic&);
  742. };
  743.  
  744. /*******************************************************************************
  745. ** CLASS TSCDynamic
  746. **
  747. ** The base class for shared-library classes with a set of common capabilities.
  748. ** This class provides the same capabilities as TStdDynamic.  It is only for
  749. ** Symantec C++ implementations
  750. ********************************************************************************/
  751.  
  752. #define kTSCDynamicID "!$scdy,1.1"
  753.  
  754. class TSCDynamic
  755. {
  756.     ASLM_COMPATIBLE
  757.  
  758.     public:
  759.         virtual                  ~ _cdecl TSCDynamic();
  760.         
  761.                 void*            operator new(size_t size, TMemoryPool* pool)    // from specified pool
  762.                                     { return SLMNewOperator(size, pool); }
  763.                 void*            operator new(size_t size)                        // from default pool
  764.                                     { return SLMNewOperator(size, 0); }
  765.                 void            operator delete(void* obj, size_t)
  766.                                     { SLMDeleteOperator(obj); }
  767.                                     
  768.         const TClassID&            GetObjectsClassID() const;
  769.         const TClassID&            GetObjectsParentClassID() const;
  770.                 size_t            GetObjectsSize() const;
  771.                 TLibrary*        GetObjectsLocalLibrary() const;
  772.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  773.                 TStandardPool*    GetObjectsLocalPool() const;
  774.                 void            SetObjectsLocalPool(TStandardPool*) const;
  775.  
  776.         virtual Boolean            _cdecl IsValid() const;
  777.         
  778.         virtual    OSErr            _cdecl Inflate(TFormattedStream&);
  779.         virtual OSErr            _cdecl Flatten(TFormattedStream&) const;
  780.         virtual TSCDynamic*        _cdecl Clone(TStandardPool*) const;
  781.         
  782.         virtual    char*            _cdecl GetVerboseName(char*) const;
  783.         virtual    void            _cdecl Dump() const;
  784.         
  785.                 void            Trace(char *formatStr, ...) const;
  786.         virtual    Boolean            _cdecl TraceControl(TraceControlType) const;
  787.                 Boolean            IsTraceOn() const;    
  788.                 Boolean            TraceOn() const;
  789.                 Boolean            TraceOff() const;
  790.     
  791.                 Boolean            IsDerivedFrom(const TClassID&) const;
  792.                 
  793.     protected:
  794.                                   _cdecl TSCDynamic();
  795.  
  796.     private:
  797.                                 TSCDynamic(const TSCDynamic&);
  798.                 void            operator=(const TSCDynamic&);
  799. };
  800.  
  801. /*    -------------------------------------------------------------------------
  802.     Inline methods for TSCDynamic
  803.     ------------------------------------------------------------------------- */
  804.  
  805.     inline Boolean TSCDynamic::IsTraceOn() const
  806.     {
  807.         return TraceControl(kTraceStatus);
  808.     }
  809.  
  810.     inline Boolean TSCDynamic::TraceOn() const
  811.     {
  812.         return TraceControl(kTraceOn);
  813.     }
  814.  
  815.     inline Boolean TSCDynamic::TraceOff() const
  816.     {
  817.         return TraceControl(kTraceOff);
  818.     }
  819.     
  820. #endif    /* __SC__ */
  821. #endif    /* __cplusplus */
  822.  
  823. /*******************************************************************************
  824. ** Class TClassID, TFunctionSetID, and TLibraryID
  825. **
  826. ** TFunctionSetID and TLibraryID are typedef'd to be the same as TClassID
  827. ********************************************************************************/
  828.  
  829. #define kMaxClassIDSize        255
  830.  
  831. #ifdef __cplusplus
  832.  
  833. const TClassID& ClassID(const char* str);    // cast a char* to a TClassID
  834.  
  835. Boolean operator==(const TClassID&, const char *);
  836. Boolean operator!=(const TClassID&, const char *);
  837. Boolean operator==(const char *, const TClassID&);
  838. Boolean operator!=(const char *, const TClassID&);
  839.  
  840. class TClassID
  841. {
  842.     public:
  843.         void*        operator new(size_t, size_t strLen, TMemoryPool* thePool = NULL)
  844.                     {
  845.                         return SLMNewOperator(strLen+1, thePool);
  846.                     }
  847.  
  848.         void*        operator new(size_t)
  849.                     {
  850.                         return SLMNewOperator(kMaxClassIDSize+1, NULL);
  851.                     }
  852.                         
  853.         void        operator delete(void* obj, size_t)
  854.                         { SLMDeleteOperator(obj); }
  855.  
  856.                     TClassID();
  857.                     TClassID(const TClassID&);
  858.  
  859.                     operator const char*() const;        // cast to a const char *
  860.  
  861.         Version        MPWC ExtractVersion() const;
  862.         size_t        MPWC GetLength() const;
  863.         
  864.         TClassID&    operator=(const TClassID&);
  865.  
  866.         Boolean        operator==(const TClassID&) const;
  867.         Boolean        operator!=(const TClassID&) const;
  868.  
  869.     private:
  870.         char                fClassIDStr[kMaxClassIDSize + 1];
  871. };
  872.  
  873. /*    -------------------------------------------------------------------------
  874.     Inline methods for TClassID
  875.     ------------------------------------------------------------------------- */
  876.  
  877.     //
  878.     // constructors
  879.     //
  880.  
  881.     inline TClassID::TClassID()
  882.     {
  883.         fClassIDStr[0] = 0;
  884.     }
  885.     
  886.     inline TClassID::TClassID(const TClassID& classID)
  887.     {
  888.         strcpy(fClassIDStr, classID.fClassIDStr);
  889.     }
  890.  
  891.     //
  892.     // cast operators
  893.     //
  894.  
  895.     inline const TClassID& ClassID(const char* str)
  896.     {
  897.         return *(const TClassID*)str;
  898.     }
  899.     
  900.     inline TClassID::operator const char *() const
  901.     {
  902.         return fClassIDStr;
  903.     }
  904.  
  905.     //
  906.     // compare operators
  907.     //
  908.     
  909.     inline Boolean TClassID::operator!=(const TClassID& classID) const
  910.     {
  911.         return !(*this == classID);
  912.     }
  913.     
  914.     inline Boolean operator!=(const TClassID& id1, const char *id2)
  915.     {
  916.         return !(id1 == ClassID(id2));
  917.     }
  918.  
  919.     inline Boolean operator!=(const char *id1, const TClassID& id2)
  920.     {
  921.         return !(id2 == ClassID(id1));
  922.     }
  923.     
  924.     inline Boolean operator==(const TClassID& id1, const char *id2)
  925.     {
  926.         return (id1 == ClassID(id2));
  927.     }
  928.     
  929.     inline Boolean operator==(const char *id1, const TClassID& id2)
  930.     {
  931.         return (id2 == ClassID(id1));
  932.     }
  933.  
  934.     //
  935.     // assignment operators
  936.     //
  937.     
  938.     inline TClassID& TClassID::operator=(const TClassID& classID)
  939.     {
  940.         strcpy(fClassIDStr, classID.fClassIDStr);
  941.         return *this;
  942.     }
  943.     
  944. #endif
  945.  
  946. /*******************************************************************************
  947. ** Class TLibraryManager
  948. **
  949. ** The user's interface to the world! 
  950. ********************************************************************************/
  951.  
  952. #ifdef __cplusplus
  953.  
  954. #define kTLibraryManagerID "!$lmgr,1.1"
  955.  
  956. class TLibraryManager : public TDynamic 
  957. {
  958.  
  959.     private:
  960.         virtual                    ~ MPWC TLibraryManager();
  961.                                 MPWC TLibraryManager(TStandardPool* = NULL, TLibraryFile* = NULL);
  962.  
  963.     public:
  964.         virtual    void            MPWC Dump() const;
  965.  
  966.         // New Methods
  967.         
  968.         virtual    void*            MPWC NewObject(const TClassID& classID,
  969.                                     OSErr* = NULL, TStandardPool* = NULL) const;
  970.         virtual    void*            MPWC NewObject(const TClassID& classID, const TClassID& baseClassID,
  971.                                     OSErr* = NULL, TStandardPool* = NULL) const;
  972.         virtual    void*            MPWC NewObject(const TFormattedStream&,
  973.                                     OSErr* = NULL, TStandardPool* = NULL) const;
  974.  
  975.         virtual TClassInfo*     MPWC GetClassInfo(const TClassID&, OSErr* = NULL) const;
  976.  
  977.         virtual OSErr            MPWC VerifyClass(const TClassID& classID, const TClassID& baseClassID) const;
  978.         virtual void*            MPWC CastObject(const void* obj, const TClassID& parentID,
  979.                                                 OSErr* = NULL) const;
  980.         virtual void*            MPWC CastToMainObject(const void* obj) const;
  981.         
  982.         virtual OSErr            MPWC LoadClass(const TClassID&, BooleanParm loadAll = false);
  983.         virtual OSErr            MPWC UnloadClass(const TClassID&);
  984.         virtual Boolean            MPWC IsClassLoaded(const TClassID&) const;
  985.  
  986.                 OSErr            LoadFunctionSet(const TFunctionSetID&, BooleanParm loadAll = false);
  987.                 OSErr            UnloadFunctionSet(const TFunctionSetID&);
  988.                 Boolean            IsFunctionSetLoaded(const TFunctionSetID&) const;
  989.         
  990.         virtual ProcPtr            MPWC GetFunctionPointer(const TFunctionSetID&,
  991.                                                    const char* funcName,
  992.                                                    OSErr* = NULL);
  993.         virtual ProcPtr            MPWC GetFunctionPointer(const TFunctionSetID&,
  994.                                                    unsigned int index,
  995.                                                    OSErr* = NULL);
  996.         
  997.         virtual OSErr            MPWC LoadLibraries(BooleanParm forceAll = true,
  998.                                                    BooleanParm doSelf = true);
  999.         virtual OSErr            MPWC UnloadLibraries();
  1000.         virtual void            MPWC ResetFunctionSet(const TFunctionSetID* = NULL);
  1001.         
  1002.         virtual Boolean            MPWC TraceLogOn();
  1003.         virtual Boolean            MPWC TraceLogOff();
  1004.         
  1005.         virtual    void            MPWC RegisterDynamicObject(TDynamic*);
  1006.         virtual    void            MPWC UnregisterDynamicObject(TDynamic*);
  1007.  
  1008.                 void            SetObjectPool(TStandardPool*);
  1009.                 TStandardPool*    GetObjectPool() const;
  1010.                 void            SetDefaultPool(TStandardPool*);
  1011.                 TStandardPool*    GetDefaultPool() const;
  1012.                 GlobalWorld        MPWC GetGlobalWorld() const;
  1013.         virtual    TLibrary*        MPWC GetLibrary() const;
  1014.         virtual    TLibraryFile*    MPWC GetLibraryFile() const;
  1015.  
  1016.     private:
  1017.                                 TLibraryManager(const TLibraryManager&);
  1018.                 void            operator=(const TLibraryManager&);
  1019.     private:        
  1020.         TStandardPool*            fPool;            // pool used for new objects and local pool
  1021.         TLibraryFile*            fLibraryFile;
  1022.         TStandardPool*            fDefaultPool;
  1023.         GlobalWorld                fGlobalWorld;
  1024.  
  1025. };
  1026.  
  1027. /*    -------------------------------------------------------------------------
  1028.     Inline Methods for TLibraryManager
  1029.     ------------------------------------------------------------------------- */
  1030.     
  1031.     inline OSErr TLibraryManager::LoadFunctionSet(const TFunctionSetID& functionSetID, BooleanParm loadAll)
  1032.     {
  1033.         return LoadClass(functionSetID, loadAll);
  1034.     }
  1035.     
  1036.     inline OSErr TLibraryManager::UnloadFunctionSet(const TFunctionSetID& functionSetID)
  1037.     {
  1038.         return UnloadClass(functionSetID);
  1039.     }
  1040.     
  1041.     inline Boolean TLibraryManager::IsFunctionSetLoaded(const TFunctionSetID& functionSetID) const
  1042.     {
  1043.         return IsClassLoaded(functionSetID);
  1044.     }
  1045.     
  1046.     inline TStandardPool* TLibraryManager::GetObjectPool() const
  1047.     {
  1048.         return fPool;
  1049.     }
  1050.     
  1051.     inline void TLibraryManager::SetObjectPool(TStandardPool* thePool)
  1052.     {
  1053.         fPool = thePool;
  1054.     }
  1055.         
  1056.     inline TStandardPool* TLibraryManager::GetDefaultPool() const
  1057.     {
  1058.         return fDefaultPool;
  1059.     }
  1060.  
  1061.     inline void TLibraryManager::SetDefaultPool(TStandardPool* thePool)
  1062.     {
  1063.         fDefaultPool = thePool;
  1064.     }
  1065.     
  1066.     inline GlobalWorld TLibraryManager::GetGlobalWorld() const
  1067.     {
  1068.         return fGlobalWorld;
  1069.     }
  1070.  
  1071. /*    -------------------------------------------------------------------------
  1072.     Inline for IsDerivedFrom
  1073.     ------------------------------------------------------------------------- */
  1074.  
  1075.     inline Boolean IsDerivedFrom(const void* obj, const TClassID& id)
  1076.     {
  1077.         return (GetLocalLibraryManager()->CastObject(obj, id) != NULL);
  1078.     }
  1079.  
  1080. /*    -------------------------------------------------------------------------
  1081.     Inline methods for TDynamic
  1082.     ------------------------------------------------------------------------- */
  1083.  
  1084.     inline Boolean TDynamic::IsDerivedFrom(const TClassID& id) const
  1085.     {
  1086.         return ::IsDerivedFrom(this, id);
  1087.     }
  1088.  
  1089.     inline const TClassID& TDynamic::GetObjectsClassID() const
  1090.     {
  1091.         return ::GetObjectsClassID(this);
  1092.     }
  1093.  
  1094.     inline const TClassID& TDynamic::GetObjectsParentClassID() const
  1095.     {
  1096.         return ::GetObjectsParentClassID(this);
  1097.     }
  1098.  
  1099.     inline size_t TDynamic::GetObjectsSize() const
  1100.     {
  1101.         return ::GetObjectsSize(this);
  1102.     }
  1103.  
  1104.     inline TLibrary* TDynamic::GetObjectsLocalLibrary() const
  1105.     {
  1106.         return ::GetObjectsLocalLibrary(this);
  1107.     }
  1108.  
  1109.     inline TLibraryFile* TDynamic::GetObjectsLocalLibraryFile() const
  1110.     {
  1111.         return ::GetObjectsLocalLibraryFile(this);
  1112.     }
  1113.  
  1114.     inline TStandardPool* TDynamic::GetObjectsLocalPool() const
  1115.     {
  1116.         return ::GetObjectsLocalPool(this);
  1117.     }
  1118.  
  1119.     inline void TDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1120.     {
  1121.         ::SetObjectsLocalPool(this, pool);
  1122.     }
  1123.     
  1124. /*    -------------------------------------------------------------------------
  1125.     Inline methods for TSimpleDynamic
  1126.     ------------------------------------------------------------------------- */
  1127.  
  1128.     inline const TClassID& TSimpleDynamic::GetObjectsClassID() const
  1129.     {
  1130.         return ((const TDynamic*)this)->GetObjectsClassID();
  1131.     }
  1132.  
  1133.     inline const TClassID& TSimpleDynamic::GetObjectsParentClassID() const
  1134.     {
  1135.         return ((const TDynamic*)this)->GetObjectsParentClassID();
  1136.     }
  1137.  
  1138.     inline size_t TSimpleDynamic::GetObjectsSize() const
  1139.     {
  1140.         return ((const TDynamic*)this)->GetObjectsSize();
  1141.     }
  1142.  
  1143.     inline TLibrary* TSimpleDynamic::GetObjectsLocalLibrary() const
  1144.     {
  1145.         return ((const TDynamic*)this)->GetObjectsLocalLibrary();
  1146.     }
  1147.  
  1148.     inline TLibraryFile* TSimpleDynamic::GetObjectsLocalLibraryFile() const
  1149.     {
  1150.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  1151.     }
  1152.  
  1153.     inline TStandardPool* TSimpleDynamic::GetObjectsLocalPool() const
  1154.     {
  1155.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  1156.     }
  1157.  
  1158.     inline void TSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1159.     {
  1160.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  1161.     }
  1162.  
  1163.     inline Boolean TSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  1164.     {
  1165.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  1166.     }
  1167.     
  1168. /*    -------------------------------------------------------------------------
  1169.     Inline methods for TStdDynamic
  1170.     ------------------------------------------------------------------------- */
  1171.  
  1172.     inline const TClassID& TStdDynamic::GetObjectsClassID() const
  1173.     {
  1174.         return ((const TDynamic*)this)->GetObjectsClassID();
  1175.     }
  1176.  
  1177.     inline size_t TStdDynamic::GetObjectsSize() const
  1178.     {
  1179.         return ((const TDynamic*)this)->GetObjectsSize();
  1180.     }
  1181.  
  1182.     inline TLibrary* TStdDynamic::GetObjectsLocalLibrary() const
  1183.     {
  1184.         return ((const TDynamic*)this)->GetObjectsLocalLibrary();
  1185.     }
  1186.  
  1187.     inline TLibraryFile* TStdDynamic::GetObjectsLocalLibraryFile() const
  1188.     {
  1189.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  1190.     }
  1191.  
  1192.     inline TStandardPool* TStdDynamic::GetObjectsLocalPool() const
  1193.     {
  1194.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  1195.     }
  1196.  
  1197.     inline void TStdDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1198.     {
  1199.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  1200.     }
  1201.     
  1202.     inline Boolean TStdDynamic::IsDerivedFrom(const TClassID& id) const
  1203.     {
  1204.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  1205.     }
  1206.  
  1207. /*    -------------------------------------------------------------------------
  1208.     Inline methods for TStdSimpleDynamic
  1209.     ------------------------------------------------------------------------- */
  1210.  
  1211.     inline const TClassID& TStdSimpleDynamic::GetObjectsClassID() const
  1212.     {
  1213.         return ((const TDynamic*)this)->GetObjectsClassID();
  1214.     }
  1215.  
  1216.     inline size_t TStdSimpleDynamic::GetObjectsSize() const
  1217.     {
  1218.         return ((const TDynamic*)this)->GetObjectsSize();
  1219.     }
  1220.  
  1221.     inline TLibrary* TStdSimpleDynamic::GetObjectsLocalLibrary() const
  1222.     {
  1223.         return ((const TDynamic*)this)->GetObjectsLocalLibrary();
  1224.     }
  1225.  
  1226.     inline TLibraryFile* TStdSimpleDynamic::GetObjectsLocalLibraryFile() const
  1227.     {
  1228.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  1229.     }
  1230.  
  1231.     inline TStandardPool* TStdSimpleDynamic::GetObjectsLocalPool() const
  1232.     {
  1233.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  1234.     }
  1235.  
  1236.     inline void TStdSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1237.     {
  1238.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  1239.     }
  1240.     
  1241.     inline Boolean TStdSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  1242.     {
  1243.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  1244.     }
  1245.     
  1246. #ifdef __SC__
  1247.  
  1248. /*    -------------------------------------------------------------------------
  1249.     Inline methods for TSCDynamic
  1250.     ------------------------------------------------------------------------- */
  1251.  
  1252.     inline Boolean TSCDynamic::IsDerivedFrom(const TClassID& id) const
  1253.     {
  1254.         return ::IsDerivedFrom(this, id);
  1255.     }
  1256.  
  1257.     inline const TClassID& TSCDynamic::GetObjectsClassID() const
  1258.     {
  1259.         return ::GetObjectsClassID(this);
  1260.     }
  1261.  
  1262.     inline const TClassID& TSCDynamic::GetObjectsParentClassID() const
  1263.     {
  1264.         return ::GetObjectsParentClassID(this);
  1265.     }
  1266.  
  1267.     inline size_t TSCDynamic::GetObjectsSize() const
  1268.     {
  1269.         return ::GetObjectsSize(this);
  1270.     }
  1271.  
  1272.     inline TLibrary* TSCDynamic::GetObjectsLocalLibrary() const
  1273.     {
  1274.         return ::GetObjectsLocalLibrary(this);
  1275.     }
  1276.  
  1277.     inline TLibraryFile* TSCDynamic::GetObjectsLocalLibraryFile() const
  1278.     {
  1279.         return ::GetObjectsLocalLibraryFile(this);
  1280.     }
  1281.  
  1282.     inline TStandardPool* TSCDynamic::GetObjectsLocalPool() const
  1283.     {
  1284.         return ::GetObjectsLocalPool(this);
  1285.     }
  1286.  
  1287.     inline void TSCDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1288.     {
  1289.         ::SetObjectsLocalPool(this, pool);
  1290.     }
  1291.     
  1292. /*    -------------------------------------------------------------------------
  1293.     Inline methods for TSCSimpleDynamic
  1294.     ------------------------------------------------------------------------- */
  1295.  
  1296.     inline const TClassID& TSCSimpleDynamic::GetObjectsClassID() const
  1297.     {
  1298.         return ((const TSCDynamic*)this)->GetObjectsClassID();
  1299.     }
  1300.  
  1301.     inline const TClassID& TSCSimpleDynamic::GetObjectsParentClassID() const
  1302.     {
  1303.         return ((const TSCDynamic*)this)->GetObjectsParentClassID();
  1304.     }
  1305.  
  1306.     inline size_t TSCSimpleDynamic::GetObjectsSize() const
  1307.     {
  1308.         return ((const TSCDynamic*)this)->GetObjectsSize();
  1309.     }
  1310.  
  1311.     inline TLibrary* TSCSimpleDynamic::GetObjectsLocalLibrary() const
  1312.     {
  1313.         return ((const TSCDynamic*)this)->GetObjectsLocalLibrary();
  1314.     }
  1315.  
  1316.     inline TLibraryFile* TSCSimpleDynamic::GetObjectsLocalLibraryFile() const
  1317.     {
  1318.         return ((const TSCDynamic*)this)->GetObjectsLocalLibraryFile();
  1319.     }
  1320.  
  1321.     inline TStandardPool* TSCSimpleDynamic::GetObjectsLocalPool() const
  1322.     {
  1323.         return ((const TSCSimpleDynamic*)this)->GetObjectsLocalPool();
  1324.     }
  1325.  
  1326.     inline void TSCSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  1327.     {
  1328.         ((const TSCSimpleDynamic*)this)->SetObjectsLocalPool(pool);
  1329.     }
  1330.  
  1331.     inline Boolean TSCSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  1332.     {
  1333.         return ((const TSCSimpleDynamic*)this)->IsDerivedFrom(id);
  1334.     }
  1335.     
  1336. #endif        /* __SC__ */
  1337. #endif        /* __cplusplus */
  1338.  
  1339. /*******************************************************************************
  1340. ** EXCEPTION Handling
  1341. **
  1342. ** Some RULES:
  1343. ** 1) Never propogate a failure outside of a constructor or destructor.
  1344. **    If your constructor or destructor can call something which fails, it
  1345. **    _must_ CATCH the failure and not re-propogate it.
  1346. ** 2) Never create an object inside of a "try" block which you cannot 
  1347. **    destroy (especially an auto object).
  1348. ** 3) if you are going to just RERAISE the exception, or Fail 
  1349. **      with a different error, you must manually call the destructors 
  1350. **    of any  auto objects that are still in scope!
  1351. ** 4) Any variables that are changed inside the "try", and which are tested
  1352. **    inside a CATCH, CATCH_ALL, or FINALLY must be declared "volatile" 
  1353. **      (Use the Volatile macro below until C++ and volatile work!)
  1354. ** 5) Never call Fail while an auto variable is in scope - it's 
  1355. **      destructor will not be called unless you call it manually.
  1356. ** 6) FINALLY is always entered after TRY unless a CATCH clause raises
  1357. **    (or re-raises) an exception (this is true even if an exception was
  1358. **    not thrown).
  1359. ********************************************************************************/
  1360.  
  1361. struct TException
  1362. {
  1363.     struct TException*    fPrev;
  1364.     size_t                fReserved;
  1365.     long                fBuffer[12];
  1366.     char*                fMessage;
  1367.     void*                fPtr;
  1368.     OSErr                fError;
  1369. };
  1370.  
  1371. #ifdef __cplusplus
  1372. extern "C" {
  1373. #else
  1374. typedef struct TException    TException;
  1375. #endif
  1376.  
  1377. void        MPWC PushException(TException*);
  1378. TException*    MPWC PopException(TException*);
  1379. Boolean        MPWC MatchException(TException*, long);
  1380.  
  1381. #if USES68KINLINES
  1382. #pragma parameter __D0 SetupException(__A0)
  1383. int SetupException(long* val) =
  1384. {
  1385.     0x43fa, 0x0008,    /* lea        *+10,a1 */
  1386.     0x48d0, 0xdefc,    /* movem.l    d2-d7/a1-a4/a6/a7,(a0) */
  1387.     0x7000            /* moveq    #0,d0 */
  1388. };
  1389. #else
  1390. int SetupException(long* val);
  1391. #endif
  1392.  
  1393. #ifdef __cplusplus
  1394. }
  1395. #endif
  1396.     
  1397. /*    -----------------------------------------------------------------
  1398.     Some important functions for exception handling
  1399.     ----------------------------------------------------------------- */
  1400.  
  1401. #ifdef __cplusplus
  1402. extern "C" {
  1403. void MPWC Fail(long err, const char* msg=NULL);
  1404. }
  1405. #else
  1406. void MPWC Fail(long err, const char* msg);
  1407. #endif
  1408.  
  1409. #ifdef __cplusplus
  1410. inline void FailNULL(void* val, long err, const char* msg=NULL) 
  1411.     if (val == 0) 
  1412.         Fail(err, msg); 
  1413. }
  1414. #else
  1415. #define FailNULL(val, err, msg)        \
  1416.     if (val == 0) { Fail(err, msg); } else {}
  1417. #endif
  1418.  
  1419. #if qDebug
  1420. #define DebugFail(err, msg)                Fail(err, msg)
  1421. #define DebugFailNULL(ptr, err, msg)    FailNULL(ptr, err, msg)
  1422. #else
  1423. #define DebugFail(err, msg)                Fail(err, NULL)
  1424. #define DebugFailNULL(ptr, err, msg)    FailNULL(ptr, err, NULL)
  1425. #endif
  1426.  
  1427.  
  1428. #define ErrorCode()                 (except.fError)
  1429. #define ErrorMessage()                (except.fMessage)
  1430. #define Volatile(x)                    ((void) &x)
  1431.  
  1432. /*    -----------------------------------------------------------------
  1433.     The RAISE/RERAISE/TRY/CATCH/CATCH_ALL/FINALLY/ENDTRY macros
  1434.     ----------------------------------------------------------------- */
  1435.  
  1436. #define RAISE(x)     Fail(x,NULL)
  1437.  
  1438. #define TRY                                                 \
  1439.     {                                                        \
  1440.         TException    except;                                    \
  1441.         Volatile(except);                                    \
  1442.         PushException(&except);                                \
  1443.         if (SetupException(except.fBuffer) == 0)            \
  1444.         {
  1445.         
  1446. #define CATCH(e)                                            \
  1447.         }                                                    \
  1448.         else if (MatchException(&except, e))                \
  1449.         { 
  1450.         
  1451.         
  1452. #define CATCH_ALL                                            \
  1453.         }                                                    \
  1454.         else                                                \
  1455.         { 
  1456.         
  1457.         
  1458. #define RERAISE                                                \
  1459.         Fail(ErrorCode(), ErrorMessage())
  1460.         
  1461. #define FINALLY                                                \
  1462.         }                                                    \
  1463.         PopException(&except);                                \
  1464.         if (ErrorCode() != kNoError) RERAISE;                \
  1465.         {
  1466.         
  1467. #define ENDTRY                                                \
  1468.         }                                                    \
  1469.         PopException(&except);                                \
  1470.     }
  1471.  
  1472. #endif
  1473.